package com.itheima.test;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;

@Slf4j
public class Tabc {
    public static void main(String[] args) throws ExecutionException, InterruptedException {


//        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
//           log.info("有返回值的异步任务");
//            try {
//                Thread.sleep(5000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            return "Hello World";
//        });
//        String result = future.get();
//        log.info("有返回值的异步任务 {}", result);
        CompletableFuture<String> async = CompletableFuture.supplyAsync(() -> {
            log.info("线程名:{}", Thread.currentThread().getName());
            return "ok";
        });

        String s = async.get();
        System.out.println(s);
    }
}
